package com.knowledgegraph.web.controller.zhongyao;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.knowledgegraph.web.controller.tool.MapDistance;
import com.knowledgegraph.zhongyao.domain.jsonDaata;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.knowledgegraph.common.annotation.Log;
import com.knowledgegraph.common.core.controller.BaseController;
import com.knowledgegraph.common.core.domain.AjaxResult;
import com.knowledgegraph.common.enums.BusinessType;
import com.knowledgegraph.zhongyao.domain.Dili;
import com.knowledgegraph.zhongyao.service.IDiliService;
import com.knowledgegraph.common.utils.poi.ExcelUtil;
import com.knowledgegraph.common.core.page.TableDataInfo;

/**
 * 附近药店Controller
 * 
 * @author ruoyi
 * @date 2023-08-20
 */
@RestController
@RequestMapping("/zhongyao/dili")
public class DiliController extends BaseController
{
    @Autowired
    private IDiliService diliService;

    /**
     * 查询附近药店列表
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:dili:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dili dili)
    {
        startPage();
        List<Dili> list = diliService.selectDiliList(dili);
        return getDataTable(list);
    }

    /**
     * 导出附近药店列表
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:dili:export')")
    @Log(title = "附近药店", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Dili dili)
    {
        List<Dili> list = diliService.selectDiliList(dili);
        ExcelUtil<Dili> util = new ExcelUtil<Dili>(Dili.class);
        util.exportExcel(response, list, "附近药店数据");
    }

    /**
     * 获取附近药店详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:dili:query')")
    @GetMapping(value = "/{dKey}")
    public AjaxResult getInfo(@PathVariable("dKey") String dKey)
    {
        return AjaxResult.success(diliService.selectDiliByDKey(dKey));
    }

    /**
     * 新增附近药店
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:dili:add')")
    @Log(title = "附近药店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dili dili)
    {
        return toAjax(diliService.insertDili(dili));
    }

    /**
     * 修改附近药店
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:dili:edit')")
    @Log(title = "附近药店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dili dili)
    {
        return toAjax(diliService.updateDili(dili));
    }

    /**
     * 删除附近药店
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:dili:remove')")
    @Log(title = "附近药店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dKeys}")
    public AjaxResult remove(@PathVariable String[] dKeys)
    {
        return toAjax(diliService.deleteDiliByDKeys(dKeys));
    }




   @GetMapping("jsonDta")
    public  List<jsonDaata>  jsonDta(@RequestParam(value = "name",required = true) String  name)
    {
        String url="https://apis.map.qq.com/ws/place/v1/search?key=YK4BZ-HVOED-RJW47-PVGFF-JC5GE-NLBFH&boundary=region(吉林市,1)&keyword="+name;
        String s = MapDistance.SendGET(url, null);
        JSONObject jsonObject = JSONObject.parseObject(s);
        List<jsonDaata> data= (List<jsonDaata>) jsonObject.get("data");
        return data ;
    }

}
